package com.woniuxy.carrental.controller;


import com.woniuxy.carrental.entity.*;
import com.woniuxy.carrental.service.WarnRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author author
 * @create 2021-10-05 17:44
 */
@RestController
public class WarnRecordController {

    @Autowired
    WarnRecordService warnRecordService;

    @GetMapping("/getWarnRecord")
    public ResponseResult<PageBean<WarnRecord>> getWarnRecord(WarnRecord warnRecord, int pageIndex, int pageSize){
        System.out.println("查询条件："+warnRecord);
        System.out.println("pageSize："+pageSize);
        System.out.println("pageIndex："+pageIndex);

        int i = warnRecordService.selectwarnRecordCountBylimit(warnRecord);
        List<WarnRecord> warnRecords = warnRecordService.selectAllwarnRecord(warnRecord, pageIndex, pageSize);
        PageBean<WarnRecord> pageBean=new PageBean();
        pageBean.setBeanList(warnRecords);
        pageBean.setPageIndex(pageSize);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);

        return new ResponseResult<PageBean<WarnRecord>>(pageBean,200,"ok");
    }


    @PostMapping("/addWarnRecord")
    public String addRenrCarIn(@RequestBody WarnRecord warnRecord){
        System.out.println(warnRecord);
        warnRecordService.addWarnRecord(warnRecord);
        return "添加成功";
    }


    @PutMapping("/updateWarnRecord")
    public String updateRenrCarIn(@RequestBody WarnRecord warnRecord){
        System.out.println(warnRecord);
        warnRecordService.updatewarnRecord(warnRecord);
        return "修改成功";
    }

    @DeleteMapping("/deleteWarnRecord/{warnid}")
    public String eletedRenrCarIn(@PathVariable ("warnid") int warnid){
        System.out.println(warnid);
        warnRecordService.delectwarnRecordByid(warnid);
        return "删除成功";
    }


    @PutMapping ("/updateWarnstart/{warnid}")
    public String updateWarnstart(@PathVariable ("warnid") int warnid){
        System.out.println(warnid);
        warnRecordService.updateStareBywarnid(warnid);
        return "修改成功";
    }


    @GetMapping("/getallEmpbyzqq")
    public List<Emp> getallEmpbyzqq(){

        return warnRecordService.getallEmpbyzqq();
    }



}
